
import 'package:usbflutter/usb/ByteBuf.dart';
import 'package:usbflutter/usb/UsbPackage.dart';
import 'package:usbflutter/usb/handler/IDevicceHandler.dart';

/// 地磅数据处理器
class WeighingDeviceHandler extends IDeviceHandler {
  WeighingDeviceHandler() {
    baudRate = 9600;
  }

  @override
  void parse(UsbPackage package) {
    final data = package.data;
    if (data == null) {
      return;
    }
    ByteBuf buf = ByteBuf.create(data);
    // 地磅的帧头
    // final flag = buf.readShort();
    // if (flag != 0x20 << 8 | 0x20) {
    //   return;
    // }
    currentValue = buf.readString(10);
  }

  @override
  String toString() {
    return "重量: $currentValue";
  }
}
